<!DOCTYPE html>
<html lang="zh">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="keywords" content="dromara.org" />
	<meta name="description" content="dromara.org" />
	<!-- 网页标签标题 -->
	<title>dromara(Open source organization)</title>
	<link rel="shortcut icon" href="/website/img/docsite.ico"/>
	<link rel="stylesheet" href="/website/build/documentation.css" />
</head>
<body>
	<div id="root"><div class="documentation-page" data-reactroot=""><header class="header-container header-container-normal"><div class="header-body"><a href="/website/en-us/index.html"><img class="logo" src="/website/img/dromara.png"/></a><div class="search search-normal"><span class="icon-search"></span></div><span class="language-switch language-switch-normal">中</span><div class="header-menu"><img class="header-menu-toggle" src="/website/img/system/menu_gray.png"/><ul><li class="menu-item menu-item-normal"><a href="/website/en-us/index.html" target="_self">Home</a><div class="sub-menu"><ul></ul></div></li><li class="menu-item menu-item-normal menu-item-normal-active"><a href="#">Document</a><div class="sub-menu"><ul><li><a href="/website/en-us/docs/soul/soul.html" target="_self">Soul</a></li><li><a href="/website/en-us/docs/hmily/index.html" target="_self">Hmily</a></li></ul></div></li><li class="menu-item menu-item-normal"><a href="/website/en-us/blog/index.html" target="_self">Blog</a><div class="sub-menu"><ul></ul></div></li><li class="menu-item menu-item-normal"><a href="/website/en-us/community/index.html" target="_self">Community</a><div class="sub-menu"><ul></ul></div></li></ul></div></div></header><section class="content-section"><div class="sidemenu" id="menu"><div class="sidemenu-toggle"><img src="https://img.alicdn.com/tfs/TB1E6apXHGYBuNjy0FoXXciBFXa-200-200.png"/></div><ul><li class="menu-item menu-item-level-1"><span>Soul</span><ul><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/soul.html" target="_self">Home  </a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/team.html" target="_self">Team</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/db.html" target="_self">Database Design</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/config.html" target="_self">Config</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/dataSync.html" target="_self">DataSync</a></li><li style="height:36px;overflow:hidden" class="menu-item menu-item-level-2"><a href="/website/en-us/docs/soul/metaData.html" target="_self">MetaData</a></li><li style="height:612px;overflow:hidden" class="menu-item menu-item-level-2"><span>User Document<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/setup.html" target="_self">Set up</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/user-http.html" target="_self">Http proxy</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/user-dubbo.html" target="_self">Dubbo proxy</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/user-springcloud.html" target="_self">Spring cloud proxy</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/selector.html" target="_self">Selector and Rule</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/user-dataSync.html" target="_self">Use data sync</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-divide.html" target="_self">Divide Plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-dubbo.html" target="_self">Dubbo plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-springcloud.html" target="_self">Spring cloud plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-rateLimiter.html" target="_self">RateLimiter plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-hystrix.html" target="_self">Hystrix plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-monitor.html" target="_self">Monitor plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-waf.html" target="_self">Waf plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-sign.html" target="_self">Sign plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-rewrite.html" target="_self">Rewrite plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/plugin-websocket.html" target="_self">Websocket plugin</a></li></ul></li><li style="height:360px;overflow:hidden" class="menu-item menu-item-level-2"><span>Developer Guide<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-filter.html" target="_self">Custom filter </a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-plugin.html" target="_self">Custom plugin</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-file.html" target="_self">File and Image</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-iphost.html" target="_self">Custom parsing IP and Host</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-result.html" target="_self">Custom result</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-sign.html" target="_self">Custom sign algorithm</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-client.html" target="_self">Developer soul client</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-thread.html" target="_self">Thread</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/dev-netty.html" target="_self">Soul optimize</a></li></ul></li><li style="height:144px;overflow:hidden" class="menu-item menu-item-level-2"><span>Community<img style="transform:rotate(0deg)" class="menu-toggle" src="/website/img/system/arrow_down.png"/></span><ul><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/contributor.html" target="_self">Contributor</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/committer.html" target="_self">Committer</a></li><li class="menu-item menu-item-level-3"><a href="/website/en-us/docs/soul/code-conduct.html" target="_self">Code conduct</a></li></ul></li></ul></li></ul></div><div class="doc-content markdown-body" id="doc-body"><h1>Motan Interface Sectioon</h1>
<ul>
<li>Introduce the jar packages into your interface project.</li>
</ul>
<pre><code class="language-xml">      <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hmily-annotation<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>{last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>Add the <code>@Hmily</code> annotation on the interface method in which you need to perform Hmily distributed transactions.</li>
</ul>
<pre><code class="language-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">HelloService</span> </span>{

    <span class="hljs-meta">@Hmily</span>
    <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">say</span><span class="hljs-params">(String hello)</span></span>;
}
</code></pre>
<h1>The project with Motan implementation</h1>
<ul>
<li>
<p>Step 1 ： Introduce the jar package of the <code>hmily</code> dependency</p>
</li>
<li>
<p>Step 2 ： Add <code>Hmily</code> configuration</p>
</li>
<li>
<p>Step 3 ： Add the specific annotation to the implementation method. you need to complete the development of <code>confirm</code> and <code>cancel</code> method, if in <code>TCC</code> mode.</p>
</li>
</ul>
<h3>Introduce The Maven dependency</h3>
<h5>Spring-Namespace</h5>
<ul>
<li>Introduce the <code>hmily-motan</code> dependency</li>
</ul>
<pre><code class="language-xml">        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hmily-motan<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
           <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>{last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<ul>
<li>make the configuration in the XML configuration file as below:</li>
</ul>
<pre><code class="language-xml">    <span class="hljs-comment">&lt;!-- set up to enable the aspectj-autoproxy --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">aop:aspectj-autoproxy</span> <span class="hljs-attr">expose-proxy</span>=<span class="hljs-string">"true"</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span> = <span class="hljs-string">"hmilyTransactionAspect"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.dromara.hmily.spring.aop.SpringHmilyTransactionAspect"</span>/&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span> = <span class="hljs-string">"hmilyApplicationContextAware"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.dromara.hmily.spring.HmilyApplicationContextAware"</span>/&gt;</span>

</code></pre>
<h5>Spring-Boot-starter</h5>
<ul>
<li>Introduce the <code>hmily-spring-boot-starter-motan</code> dependency</li>
</ul>
<pre><code class="language-xml">        <span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.dromara<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>hmily-spring-boot-starter-motan<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span>
           <span class="hljs-tag">&lt;<span class="hljs-name">version</span>&gt;</span>{last.version}<span class="hljs-tag">&lt;/<span class="hljs-name">version</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span>
</code></pre>
<h3>Introduce the <code>Hmily</code> configuration</h3>
<ul>
<li>
<p>new a configuration file named <code>hmily.yml</code> under the <code>resource</code> directory of the current project</p>
</li>
<li>
<p>the specific parameter configuration can refer to <a href="config_en.md">configuration detail</a>,<a href="config-local_en.md">Local configuration mode</a>, <a href="config-zookeeper_en.md">Zookeeper configuration mode</a>, <a href="config-nacos_en.md">nacos configuration mode</a>,<a href="config-apollo_en.md">apollo configuration mode</a></p>
</li>
</ul>
<h3>Add annotations on the implementation interface</h3>
<p>We have completed the integration and configuration described above, and the next let's explain how to use it in detail.</p>
<h5>TCC Mode</h5>
<ul>
<li>
<p>Add <code>@HmilyTCC (confirmMethod = &quot;confirm&quot;, cancelMethod = &quot;cancel&quot;)</code> annotation to the concrete implementation of the interface method identified by '@Hmily'.</p>
</li>
<li>
<p><code>confirmMethod</code> : the method name for confirm，The method parameter list and return type should be consistent with the identification method.</p>
</li>
<li>
<p><code>cancelMethod</code> :  the method for cancel，The method parameter list and return type should be consistent with the identification method.</p>
</li>
<li>
<p>The <code>TCC</code> mode should ensure the idempotence of the <code>confirm</code> and <code>cancel</code> methods,Users need to develop these two methods by themselves,The confirmation and rollback behavior of all transactions are completely up tp users.The Hmily framework is just responsible for making calls.</p>
</li>
</ul>
<pre><code class="language-java">
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HelloServiceImpl</span> <span class="hljs-keyword">implements</span> <span class="hljs-title">HelloService</span>  </span>{

    <span class="hljs-meta">@HmilyTCC</span>(confirmMethod = <span class="hljs-string">"sayConfrim"</span>, cancelMethod = <span class="hljs-string">"sayCancel"</span>)
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">say</span><span class="hljs-params">(String hello)</span> </span>{
         System.out.println(<span class="hljs-string">"hello world"</span>);
    }
    
    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">sayConfrim</span><span class="hljs-params">(String hello)</span> </span>{
         System.out.println(<span class="hljs-string">" confirm hello world"</span>);
    }

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">sayCancel</span><span class="hljs-params">(String hello)</span> </span>{
         System.out.println(<span class="hljs-string">" cancel hello world"</span>);
    }
}
</code></pre>
<h1>The users for using Motan annotation</h1>
<p>For the users using the '@MotanReferer' annotation to inject the Motan service, please note that you may need to do configuration as below:</p>
<h4>The users for using Spring Namespace</h4>
<p>In your xml configuration, you need to inject the <code>org.dromara.hmily.spring.annotation.RefererAnnotationBeanPostProcessor</code> into a spring bean.</p>
<pre><code class="language-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">bean</span> <span class="hljs-attr">id</span> = <span class="hljs-string">"refererAnnotationBeanPostProcessor"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"org.dromara.hmily.spring.annotation.RefererAnnotationBeanPostProcessor"</span>/&gt;</span>
</code></pre>
<h4>The users for using Spring Boot</h4>
<p>You need to enable the annotation support in the YML configuration file:</p>
<pre><code class="language-yml"><span class="hljs-string">hmily.support.rpc.annotation</span> <span class="hljs-string">=</span> <span class="hljs-literal">true</span> 
</code></pre>
<p>or inject it into the project explicitly:</p>
<pre><code class="language-java"><span class="hljs-meta">@Bean</span>
<span class="hljs-function"><span class="hljs-keyword">public</span> BeanPostProcessor <span class="hljs-title">refererAnnotationBeanPostProcessor</span><span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> RefererAnnotationBeanPostProcessor();
}
</code></pre>
<h2>TAC Mode(Under development, not released)</h2>
<ul>
<li>Add <code>@HmilyTAC</code> annotation to the concrete implementation of the interface method identified by '@Hmily'.</li>
</ul>
<h2>Important Notes</h2>
<p>Before invoking any RPC calls, when you need to aggregate RPC calls to be a distributed transaction, you need to add an annotation to the method of aggregate RPC calls which means to enable a global transaction.</p>
<h4>Load balance</h4>
<ul>
<li>
<p>If the service is deployed with several nodes, the load balance algorithm is better to use <code>hmily</code>, so that the calls of <code>try</code>, <code>confirm</code>, and <code>cancel</code> will fall on the same node to make full use of the cache and improve efficiency.</p>
</li>
<li>
<p>There are serval load balance algorithms supported such as <code>hmilyActiveWeight</code>, <code>hmilyConfigurableWeight</code>,  <code>hmilyConsistent</code>, <code>hmilyLocalFirst</code>, <code>hmilyRandom</code>, <code>hmilyRoundRobin</code>, all of which are inherited from Motan's native algorithm.</p>
</li>
</ul>
<pre><code class="language-xml">   <span class="hljs-tag">&lt;<span class="hljs-name">motan:reference</span>  <span class="hljs-attr">interface</span>=<span class="hljs-string">"xxx"</span>  <span class="hljs-attr">id</span>=<span class="hljs-string">"xxx"</span> <span class="hljs-attr">loadbalance</span>=<span class="hljs-string">"hmilyActiveWeight"</span>/&gt;</span>           
</code></pre>
<h4>Set up to never try</h4>
<ul>
<li>the Motan interface which required distributed transaction should be set to never retry by caller.</li>
</ul>
<pre><code class="language-xml">   <span class="hljs-tag">&lt;<span class="hljs-name">motan:reference</span>  <span class="hljs-attr">interface</span>=<span class="hljs-string">"xxx"</span>  <span class="hljs-attr">id</span>=<span class="hljs-string">"xxx"</span> <span class="hljs-attr">retries</span>=<span class="hljs-string">"0"</span>/&gt;</span>           
</code></pre>
<h4>Exception</h4>
<ul>
<li>Do not catch any exceptions of the <code>try</code>, <code>confirm</code>, <code>cancel</code> method by yourself. Any exceptions should be thrown to the Hmily framework to handle.</li>
</ul>
</div></section><footer class="footer-container"><div class="footer-body"><img src="/website/img/dromara.png"/><div class="cols-container"><div class="col col-12"><h3>Disclaimer</h3><p>Any unit or individual reprint all relevant information of this website, please indicate the source.</p></div><div class="col col-6"><dl><dt>Document</dt><dd><a href="/website/en-us/docs/soul/soul.html" target="_self">Overview </a></dd><dd><a href="/website/en-us/docs/soul/soul.html" target="_self">Stat up</a></dd><dd><a href="/website/en-us/docs/soul/soul.html" target="_self">Developer Guide</a></dd></dl></div><div class="col col-6"><dl><dt>Resource</dt><dd><a href="/website/en-us/blog/index.html" target="_self">Blog</a></dd><dd><a href="/website/en-us/community/index.html" target="_self">Community</a></dd></dl></div></div><div class="copyright"><span>Copyright ©2020 xiaoyu@apache.org by xiaoyu</span></div></div></footer></div></div>
	<script src="https://f.alicdn.com/react/15.4.1/react-with-addons.min.js"></script>
	<script src="https://f.alicdn.com/react/15.4.1/react-dom.min.js"></script>
	<script>
		window.rootPath = '/website';
  </script>
	<script src="/website/build/documentation.js"></script>
</body>
</html>